﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
using UCS.ArtificialInteligence.AI;
using UCS.ArtificialInteligence.NumbersProblem.Model;

namespace UCS.ArtificialInteligence.NumbersProblem.View.Commands
{
    public class BlindSearchCommand : ICommand
    {
        public bool CanExecute(object parameter)
        {
            return true;
        }

        public event EventHandler CanExecuteChanged;

        public void Execute(object parameter)
        {
            //var numbersBoard = new NumbersBoard(new int[,] { { 1, 2, 3 }, { 6, 5, 4 }, { 8, 7, 0 } });
            var numbersBoard = new NumbersBoard(new int[,] { { 5, 2, 1 }, { 4, 6, 7 }, { 8, 0, 3 } });
            var numbersProblem = new NumbersProblem.Model.NumbersProblem(numbersBoard);

            //BlindSearch search = new BlindSearch(numbersProblem);
            //IAIList<ProblemStateBorder> list = new AmplitudeList<ProblemStateBorder>();

            //var res = search.FindFirst(list);

            //foreach (var item in res)
            //    Console.WriteLine(item.ToString());

            AStarSearch search = new AStarSearch();
            var lastState = search.Find(numbersProblem);

            var currentState = lastState;
            Stack<string> stack = new Stack<string>();
            while (currentState != null)
            {
                stack.Push(currentState.ToString());
                currentState = currentState.Parent;
            }

            try
            {
                while (true)
                    Console.WriteLine(stack.Pop());
            }
            catch (InvalidOperationException)
            {
            }
        }
    }
}
